package com.kizuki.redis;

import com.alibaba.fastjson.JSON;
import com.kizuki.io.SuperMan;
import com.kizuki.utils.SerializeUtils;
import org.junit.Test;
import redis.clients.jedis.Jedis;

public class TestSerializable {

    @Test
    public void testIo(){
        Jedis jedis = new Jedis("localhost");
        jedis.flushDB();

        SuperMan obj1 = new SuperMan("迪迦", 100);
        SuperMan obj2 = new SuperMan("盖亚", 98);

        jedis.set("kizuki".getBytes(), SerializeUtils.serialize(obj1));
        jedis.set("madao".getBytes(), SerializeUtils.serialize(obj2));

        SuperMan deSerialize = (SuperMan)SerializeUtils.deSerialize(jedis.get("kizuki".getBytes()));
        System.out.println("在redis中的对象为：" + deSerialize);
    }

    @Test
    public void testJson(){
        Jedis jedis = new Jedis("localhost");
        jedis.flushDB();

        SuperMan obj1 = new SuperMan("迪迦", 100);
        jedis.set("kizuki", JSON.toJSONString(obj1));
        String kizuki = jedis.get("kizuki");
        System.out.println("在redis中的对象为：" + JSON.parseObject(kizuki, SuperMan.class));
    }


}
